import requests
import sys

def download_file(url):
    response = requests.get(url)
    if response.status_code == 200:
        data = response.json()
        if 'download_url' in data:
            file_response = requests.get(data['download_url'])
            if file_response.status_code == 200:
                filename = 'geometry_shp_file.geojson'
                with open(filename, 'wb') as f:
                    f.write(file_response.content)
                print(f"File downloaded: {filename}")
            else:
                print("Error: Failed to download the actual file content.")
        else:
            print("Error: download_url field not found in the response.")
    else:
        print(f"Failed to download file from {url}")

if __name__ == "__main__":
    print("Arguments passed to the script are:", sys.argv)
    if len(sys.argv) != 2:
        print("Usage: python GeometryData.py <URL>")
        sys.exit(1)

    url = sys.argv[1]
    download_file(url)
